import * as types from './mutations-type'
import {
  formDatRouter
} from 'utils'
import _router from 'project/admin/router'
import {
  locationGet
} from 'common/js/cache';
const mutations = {
  [types.SET_ADMIN_INFO](state, info) {
    state.adminInfo = info || {}
  },
  [types.SET_NAV_TITLE_LIST](state, route) {
    console.log(state.navTitleList, 'state.navTitleList')
    let temp = true;
    state.navTitleList.some((item, index) => {
      if (item.meta === route.meta) {
        temp = false;
        return true;
      }
    })
    // temp ? '' : state.navTitleList.push(route)
    temp ? state.navTitleList.push(route) : ''
    console.log(state.navTitleList, 'state.navTitleList')
  },

  [types.REMOVE_NAV_TITLE_LIST](state, list) {
    // console.log(state.navTitleList, 'state.navTitleList')
    state.navTitleList = list
  },
  [types.SET_RE_LOGIN](state, bool) {
    state.reLogin = bool
  },
  [types.SET_ROUTER](state, routerList) {
    // state.reLogin = bool
    let router = formDatRouter(routerList)
    console.log('%c gc_router=>: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;',router);
    // _router.options.routes[2].children = router;
    // _router.options.routes[2].redirect = {
    //   name:router[0].name
    // }
    let index = {
      path: '/',
      name: '/',
      meta: '首页',
      component: r => require.ensure([], () => r(require('project/admin/views/index/index'))),
      redirect: {
        name: router[0].name
      },
      children: router
    }
    _router.addRoutes([index]);
    if (locationGet('isLogin')) {
      // _router.replace('/')
      // console.log('addrouter', _router.options.routes[2]);

    }
    state.routes = router
  }
}

export default mutations
